package com.briup.cms.web.controller;


import com.briup.cms.bean.Carousel;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import com.briup.cms.service.ICarouselService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @zhushi
 * @Author kongbai
 * @Date 2021/7/17 20:14
 * @Versiom 1.0
 */
@Api(tags = "轮播图相关接口")
@RestController
@RequestMapping("/auth/carousel")

public class CarousController {
    @Autowired
    private ICarouselService carouselService;


    @ApiOperation(value = "通过id删除轮播图")
    @DeleteMapping("/deleteById")
    public Message deleteById(Integer id){
        carouselService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "查询所有已经启用的轮播图",notes = "不分页")
    @GetMapping("/find/yes")
    public Message find(){
        List<Carousel> list= carouselService.findYesCarousel();
        return MessageUtil.success(list);
    }

    @ApiOperation(value = "查询所有轮播图",notes = "分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页",required = true,paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "每页大小",required = true,paramType = "query")
    })
    @GetMapping("/page/query")
    public Message query(int pageNum,int pageSize){
        PageInfo<Carousel> c = carouselService.findAll(pageNum,pageSize);
        return MessageUtil.success(c);
    }


    @ApiOperation(value = "保存轮播图信息")
    @PostMapping("/save")
    public Message save(Carousel carousel){
        carouselService.saveCarousel(carousel);
        return MessageUtil.success(carousel);
    }

    @ApiOperation(value = "更新轮播图信息")
    @PutMapping("/update")
    public Message update(Carousel carousel){
        carouselService.updateCarousel(carousel);
        return MessageUtil.success(carousel);
    }





}
